// 拷贝文件
// eslint-disable-next-line @typescript-eslint/no-var-requires
const {exec} = require('child_process');

// exec: 执行命令
// eslint-disable-next-line @typescript-eslint/no-var-requires
const {promisify} = require('util');

// promisify : 返回promise

(async ()=>{
  try{
    await promisify(exec)('rm -rf ./dist');
    console.log('删除成功');
    // 1 . 打包
    await promisify(exec)('npm run build');
    console.log('打包成功');
    // 3 . 多一个.git的文件
    await promisify(exec)('cd ./dist && git init');
    // 4. 有些文件不需要提交
    await promisify(exec)('cd ./dist && echo "index.html" >> .gitignore');
    // 5. 提交到git缓存
    await promisify(exec)('cd ./dist && git add .');
    await promisify(exec)('cd ./dist && git commit -m "init"');
    console.log('提交');
    await promisify(exec)('cd ./dist && git branch -M main');
    await promisify(exec)('cd ./dist && git remote add origin git@github.com:IceRain-mvc/cdn_class2104a.git');
    // 强制推送
    await promisify(exec)('cd ./dist && git push -u origin main --force');

    // https://cdn.jsdelivr.net/gh/IceRain-mvc/cdn_class2104a/assets/index.8a9ca9ab.js
  }catch(error){
    console.log(error);
  }
})();